<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport"   content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>登录</title>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/login/login.css" rel="stylesheet">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->
    <script>
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    </script>
</head>
<body class="signin">
<div class="signinpanel">
    <div class="row">
        <div class="col-sm-3"></div>
        <div class="col-sm-5">
            <form id="signupForm">
                <h3 class="text-center">用户登录</h3>
                <p class="m-t-md text-center">欢迎登录后台管理系统</p>
                <input type="text" name="username" class="form-control uname" />
                <input type="password" name="password"
                       class="form-control pword m-b"/>
                <a id="login" class="btn btn-login btn-block">登录</a>
            </form>
        </div>
    </div>
    <div class="signup-footer">
        <div class="pull-left"> </div>
    </div>
</div>
<!-- 全局js -->
<script src="/static/jquery/jquery.min.js"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<!-- jQuery Validation plugin javascript-->
<script src="/static/jquery/validate/jquery.validate.min.js" ></script>
<script src="/static/layerui/layer.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#login").on('click',function(){$("#signupForm").submit();});
        validateRule();
        $("body").keydown(keyDownLogon);
    });

    $.validator.setDefaults({
        submitHandler: function () {
            login();
        }
    });

    function login() {
        $.ajax({
            type: "POST",
            url:  "/login",
            data: $('#signupForm').serialize(),
            success: function (responseUtil) {
                console.log(responseUtil)
                 if (responseUtil.code == 0) {
                    var index = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                   window.location.href = '/index';
                } else {
                    layer.msg(responseUtil.msg);
                }
            },
        });
    }

    function keyDownLogon(){
        if (event.keyCode == "13") {
            $("#login").trigger('click');
        }
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                username: {
                    required: true
                },
                password: {
                    required: true
                }
            },
            messages: {
                username: {
                    required: icon + "请输入您的用户名",
                },
                password: {
                    required: icon + "请输入您的密码",
                }
            }
        })
    }
</script>
</body>
</html>
